package com.itxx.treeset;

import com.itxx.domain.Student;

import java.util.Comparator;
import java.util.Locale;
import java.util.TreeSet;

public class Test1 {
    public static void main(String[] args) {
        TreeSet<Student> treeSet = new TreeSet<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                int result = o1.getSum() - o2.getSum();
                if (result == 0) {
                    result = o1.getChinese() - o2.getChinese();
                }
                if (result == 0) {
                    result = o1.getMath() - o2.getMath();
                }
                if (result == 0) {
                    result = o1.getEnglish() - o2.getEnglish();
                }
                if (result == 0) {
                    result = o1.getName().compareTo(String.valueOf(Locale.CHINA)) - o2.getName().compareTo(String.valueOf(Locale.CHINA));
                }
                return result;
            }
        });
        treeSet.add(new Student("张三", 100, 100, 100));
        treeSet.add(new Student("李四", 99, 100, 100));
        treeSet.add(new Student("阿三", 100, 100, 100));
        treeSet.add(new Student("李三", 100, 99, 100));
        for (Student student : treeSet) {
            System.out.println(student + "总分为" + student.getSum());
        }
    }
}
